package controller

import (
	"ez/apps/running/auto/controller"
	running "ez/apps/running/document"
	"ez/apps/running/service"
	"ez/custom/cc"
	"gitee.com/dreamwood/ez-go/ez"
)

type AppVersionController struct {
	controller.AppVersionAutoController
}

func init() {
	c := &AppVersionController{}
	c.SetRouteParam("/running", "/admin", "AppVersion")
	ez.CreateApi(c.AdminGet(), c.GetAction).SetRouterName("[running]发布版本_创建")
	ez.CreateApi(c.AdminList(), c.ListAction).SetRouterName("[running]发布版本_列表")
	ez.CreateApi(c.AdminSave(), c.SaveAction).SetRouterName("[running]发布版本_保存")
	ez.CreateApi(c.AdminCopy(), c.CopyAction).SetRouterName("[running]发布版本_复制")
	ez.CreateApi(c.AdminUpdate(), c.UpdateAction).SetRouterName("[running]发布版本_更新")
	ez.CreateApi(c.AdminChoice(), c.ChoiceAction).SetRouterName("[running]发布版本_选项")
	ez.CreateApi(c.AdminDelete(), c.DeleteAction).SetRouterName("[running]发布版本_删除")
	ez.CreateApi(c.AdminUnDelete(), c.UnDeleteAction).SetRouterName("[running]发布版本_恢复")
	ez.CreateApi(c.AdminDestroy(), c.DestroyAction).SetRouterName("[running]发布版本_销毁")
	ez.CreateApi(c.AdminUpdateMany(), c.UpdateManyAction).SetRouterName("[running]发布版本_更新_批量")
	ez.CreateApi(c.AdminDeleteMany(), c.DeleteManyAction).SetRouterName("[running]发布版本_删除_批量")
	ez.CreateApi(c.AdminDestroyMany(), c.DestroyManyAction).SetRouterName("[running]发布版本_销毁_批量")
	ez.CreateApi(c.AdminApi("/AppVersion/start_ftp"), c.StartFtpAction).SetRouterName("[running]发布版本_启动FTP")
	ez.CreateApi(c.AdminApi("/AppVersion/stop_ftp"), c.StopFtpAction).SetRouterName("[running]发布版本_关闭FTP")

}

// func (c AppVersionController) AccessControl(session *ez.Session) { /* 在这里面重构 */ }
// func (c AppVersionController) GetAction(session *ez.Session) { /* 在这里面重构 */ }
// func (c AppVersionController) ListAction(session *ez.Session) { /* 在这里面重构 */ }
func (c AppVersionController) StartFtpAction(session *ez.Session) {
	this := cc.New(session)
	id := this.GetId()
	crud := running.NewAppVersionCrud(session)
	find, e := crud.FindId(id)
	if this.Try(e) {
		return
	}
	find.LoadApp()
	service.StartFtp(find.App.Root+"/"+find.Dir, find.FtpPort, find.FtpUser, find.FtpPass)
	this.ReturnSuccess("ok", nil)
}
func (c AppVersionController) StopFtpAction(session *ez.Session) {
	this := cc.New(session)
	id := this.GetId()
	crud := running.NewAppVersionCrud(session)
	find, e := crud.FindId(id)
	if this.Try(e) {
		return
	}
	service.StopFtp(find.FtpPort)
	this.ReturnSuccess("ok", nil)
}
